package edu.ustb.filter;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

@WebFilter("/admin/*")
public class AdminLoginFilter implements Filter {


    @Override
    public void init(FilterConfig filterConfig) throws ServletException {

    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        /*HttpServletRequest httpServletRequest = (HttpServletRequest) servletRequest;
        HttpServletResponse httpServletResponse = (HttpServletResponse) servletResponse;
        //判断是否登录
        //否则跳转到登录页面
        HttpSession session = httpServletRequest.getSession();
        Object admin = session.getAttribute("admin");
        if (admin == null) {
            httpServletResponse.sendRedirect(httpServletRequest.getContextPath() + "/adminlogin.jsp");
        }
        else
        {
            //放行
            filterChain.doFilter(httpServletRequest,httpServletResponse);
        }*/
        filterChain.doFilter(servletRequest,servletResponse);
    }

    @Override
    public void destroy() {

    }
}
